package com.karina.visualization.chart.skins;

import com.karina.visualization.chart.client.Graphics;
import com.karina.visualization.chart.model.ChartModel;

public class ChartPaneSkinImpl<M extends ChartModel<?>> extends
		ChartPaneSkin<M> {

	public ChartPaneSkinImpl() {
	}

	@Override
	public void draw(Graphics graphics) {
		// graphics.clear();
		graphics.saveContext();

		drawbackground(graphics);

		graphics.restoreContext();
	}

	private void drawbackground(Graphics graphics) {
		M data = getData();

		int y = 0;
		int x = data.getX();
		int width = (data.getWidth() + x);
		int height = data.getY() + data.getHeight();
		graphics.saveContext();
		graphics.beginPath();
		graphics.fillStyle(255, 255, 255, 1);
		graphics.fillRect(x, y, width, height);
		graphics.endPath();
		graphics.restoreContext();
	}

	@Override
	public void cleanup(Graphics graphics) {
		// graphics.clear();
	}

	@Override
	public void refresh(Graphics graphics) {
		cleanup(graphics);
		draw(graphics);

	}

}
